<%@ page contentType="text/html; charset=utf-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="s" uri="http://stripes.sourceforge.net/stripes.tld" %>
 
<f:message var="headline" key="ghosts.ghosts"/>
<s:layout-render name="/content.jsp" nadpis="${headline}">
    <s:layout-component name="telo">
        <s:useActionBean beanclass="cz.muni.fi.hauntedhousesweb.web.GhostsActionBean" var="actionBean"/>
        <s:useActionBean beanclass="cz.muni.fi.hauntedhousesweb.web.SkillsActionBean" var="skillsBean"/>
        <s:useActionBean beanclass="cz.muni.fi.hauntedhousesweb.web.HousesActionBean" var="housesBean"/>
        <div class="search">
        <s:form beanclass="cz.muni.fi.hauntedhousesweb.web.GhostsActionBean" class="search">
            <s:text name="findThis" />
            <s:submit name="search" class="button"><f:message key="global.search"/></s:submit>
        </s:form>
        </div>
        
        <table class="zakladni">
            <tr>
                <th class=""><f:message key="ghosts.id"/></th>
                <th><f:message key="ghosts.name"/></th>
                <th><f:message key="ghosts.hauntingFrom"/></th>
                <th><f:message key="ghosts.hauntingTo"/></th>
                <th><f:message key="ghosts.power"/></th>
                <th><f:message key="ghosts.skill"/></th>
                <th><f:message key="ghosts.house"/></th>
                <th><f:message key="ghosts.description"/></th>                
            </tr>
            <c:forEach items="${actionBean.ghosts}" var="ghost">
                <tr>
                    <td>${ghost.id}</td>
                    <td><c:out value="${ghost.name}"/></td>
                    <td><c:out value="${ghost.hauntingFrom}"/></td>
                    <td><c:out value="${ghost.hauntingTo}"/></td>
                    <td><c:out value="${ghost.power}"/>%</td>
                    <td><c:out value="${ghost.skill.name}"/></td>
                    <td><c:out value="${ghost.house.name}"/></td>
                    <td><c:out value="${ghost.description}"/></td>
                    <c:if test="${pageContext.request.isUserInRole('ROLE_ADMIN')}" >
                        <td class="edit"><s:link beanclass="cz.muni.fi.hauntedhousesweb.web.GhostsActionBean" event="delete" ><s:param name="ghost.id" value="${ghost.id}"/><f:message key="ghosts.delete"/></s:link> </td>
                        <td class="edit"><s:link beanclass="cz.muni.fi.hauntedhousesweb.web.GhostsActionBean" event="edit" ><s:param name="ghost.id" value="${ghost.id}"/><f:message key="ghosts.edit"/></s:link> </td>
                    </c:if>
                </tr>
            </c:forEach>
        </table>
        
        <c:if test="${pageContext.request.isUserInRole('ROLE_ADMIN')}" >
        <s:form beanclass="cz.muni.fi.hauntedhousesweb.web.GhostsActionBean">
            <fieldset><legend><f:message key="ghosts.addnew"/></legend>
                <%@include file="formGhost.jsp"%>
            <s:submit name="add" class="button"><f:message key="ghosts.add"/></s:submit>
            </fieldset>
        </s:form>    
        </c:if>
            
    </s:layout-component>
</s:layout-render>
